layui.use(['form', 'layer'], function () {
    var form = layui.form,
        layer = parent.layer === undefined ? layui.layer : parent.layer,
        $ = layui.jquery;

    // layer.alert('测试账号：admin 密码：123456', {
    // 	  skin: 'layui-layer-molv' //样式类名
    // 	  ,closeBtn: 0,
    // 	  offset: 't',
    // 	  anim: 6
    // 	})
    //登录按钮事件
    form.on("submit(login)", function (data) {
        // var param = $("#form").parseForm();
        var userName = $("#username").val();
        var password = $("#password").val();
        var vcode = $("#vcode").val();

        alert(userName + ",password =" + password+",vcode =" + vcode);

        $.ajax({
            type: "get",
            url: "/irs/sys/login?username="+userName+"&password="+password+"&vcode="+vcode,
            // data:{
            //     "username":userName,
            //     "password":password,
            //     "vcode":vcode
            // },
            //contantType: "application/json", //设置请求参数格式
            dataType:"json",
            success: function (result) {
                if (result.code == 0) {//登录成功
                    parent.location.href = '/irs/sys/index';
                } else{
                    layer.msg(result.msg, {icon: 5});
                    refreshCode();
                }
            }
        });
        //防止页面跳转
        return false;
    })
});

/**
 * 刷新验证码
 */
function refreshCode(){
    var captcha = document.getElementById("captcha");
    captcha.src = "/irs/sys/vcode?t=" + new Date().getTime();
}
